package com.goldgov.synchronous.service.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.goldgov.synchronous.dao.FlowLearnSynchronousDao;
import com.goldgov.synchronous.service.FlowLearnParams;
import com.goldgov.synchronous.service.FlowLearnSynchronous;
import com.goldgov.synchronous.service.FlowLearnSynchronousService;
import com.goldgov.utils.PropertyUtil;
@Service
public class FlowLearnSynchronousServiceImpl implements FlowLearnSynchronousService {
	
	Log logger = LogFactory.getLog(getClass());
	
	@Autowired
	private FlowLearnSynchronousDao flowLearnSynchronousDao;
	
	/** 
	 * @Description: TODO
	 * @author hanxiangyu
	 * @date 2018年11月28日 下午5:37:09 
	 */
	@Override
	public void lddySynchronousStoreBasicData() throws Exception {
			FlowLearnParams flowLearnParams = new FlowLearnParams();
			flowLearnParams.setSearchOrgID("-1");
			long startTime=System.currentTimeMillis();   //获取开始时间
//			this.saveOrUpdate(flowLearnParams, date);
			this.circulationSaveOrUpdate(flowLearnParams);
			long endTime=System.currentTimeMillis(); //获取结束时间
			logger.info("统计完成用时： "+(endTime-startTime)+"ms");
	}
	

	
	
	public void circulationSaveOrUpdate(FlowLearnParams flowLearnParams) throws Exception {
		long startTime=System.currentTimeMillis();   //获取开始时间
		List<FlowLearnSynchronous> list = flowLearnSynchronousDao.findFlowLearnSynchronousList(flowLearnParams);
		long endTime=System.currentTimeMillis();   //获取开始时间
		logger.info("列表查询用时： "+(endTime-startTime)+"ms========列表长度="+list.size()+"==========");
		for (FlowLearnSynchronous flowLearnSynchronous : list) {
//			flowLearnSynchronous.setLearnDate(date);
			//判断是否存在此记录
			FlowLearnSynchronous learnSynchronous = flowLearnSynchronousDao.findFlowLearnSynchronousById(flowLearnSynchronous.getOrganizationId(), null);
			if (PropertyUtil.objectNotEmpty(learnSynchronous)) {//存在是进行更新
				flowLearnSynchronousDao.updateFlowLearnSynchronous(flowLearnSynchronous);
			} else { //不存在进行新增
				flowLearnSynchronousDao.addFlowLearnSynchronous(flowLearnSynchronous);
			}
			flowLearnParams.setSearchOrgID(flowLearnSynchronous.getOrganizationId());
			this.circulationSaveOrUpdate(flowLearnParams);
		}
	} 
	
	
	
	
	

	/**
	  * 组织学习情况统计
	  * @date 2018年11月29日 下午5:25:24 
	  * @author hanxiangyu
	  * @throws Exception
	  */
	public void orgLearinStatistics() throws Exception{
		 
		 
	}

	
	
	
}
